package sz.szsmk.citizencard.ui.dialogs;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.chenenyu.router.Router;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.ui.newversion.config.Constants;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

/**
 * author : hyt
 * date : 2020/6/29
 * description :
 */
public class ECardNoOpenDialog extends AppCompatActivity {

    ImageView dismiss_btn;

    TextView elec_card_action_txt;

    RelativeLayout action_layout;
    Dialog dialog;
    View inflate;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); //去除这个Activity的标题栏
        setContentView(R.layout.activity_nulllayout);

        dialog = new Dialog(this, R.style.midDialogStyle);
        inflate = LayoutInflater.from(this).inflate(R.layout.dialog_elec_card_sign_up, null);
        dialog.setContentView(inflate);

        //获取当前Activity所在的窗体
        Window dialogWindow = dialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity( Gravity.CENTER);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = MATCH_PARENT;
        //将属性设置给窗体
        dialogWindow.setAttributes(lp);

        dismiss_btn = inflate.findViewById(R.id.dismiss_btn);
        action_layout = inflate.findViewById(R.id.action_layout);
        elec_card_action_txt = inflate.findViewById(R.id.elec_card_action_txt);

        dismiss_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                finish();
            }
        });
        action = getIntent().getIntExtra("action",0);
        if (action == 0) {
            elec_card_action_txt.setText("您尚未开通市民卡扫码乘车功能");
        } else {
            elec_card_action_txt.setText("您尚未完成电子市民卡首次充值");
        }
        action_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (action==1){
                    Router.build("firstrecharge").go(getBaseContext());
                }else if (action ==0){
                    Router.build(Constants.BINDBANKCARDACTIVITY).go(getBaseContext());
                }
                dialog.dismiss();
                finish();
            }
        });
        if (!this.isFinishing() && !dialog.isShowing()) {
            dialog.show();
        }
    }

    private int action = 0;
    public void setAction(int action) {
        this.action = action;
    }


}
